package com.mtbu.bean.base;
import java.util.*;
import java.text.SimpleDateFormat;
import org.json.JSONObject;
import my.json.core.JsonAble;
public abstract class BppCataBase implements JsonAble {
    private Map<String, Object> dirtyProperties = new HashMap<String, Object>();
    //自增ID
    private int id = 0;
    //父ID
    private int pID = 0;
    //分类名称
    private String title = "";
    //
    private String firstPY = "";
    //排序号
    private int rank = 0;
    public int getId(){
        return this.id;
    }
    public void setId(int id){
        this.id = id;
    }
    public int getPID(){
        return this.pID;
    }
    public void setPID(int pID){
        this.pID = pID;
        dirtyProperties.put("pID", pID);
    }
    public String getTitle(){
        return this.title;
    }
    public void setTitle(String title){
        this.title = title;
        dirtyProperties.put("title", title);
    }
    public String getFirstPY(){
        return this.firstPY;
    }
    public void setFirstPY(String firstPY){
        this.firstPY = firstPY;
        dirtyProperties.put("firstPY", firstPY);
    }
    public int getRank(){
        return this.rank;
    }
    public void setRank(int rank){
        this.rank = rank;
        dirtyProperties.put("rank", rank);
    }
    public Map<String, Object> getDirtyProperties() {
        return this.dirtyProperties;
    }
    public JSONObject toJSON() throws Exception {
        JSONObject json = new JSONObject();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        json.put("id", this.getId());
        json.put("pID", this.getPID());
        if(title!=null){
           json.put("title",this.getTitle());
        }
        if(firstPY!=null){
           json.put("firstPY",this.getFirstPY());
        }
        json.put("rank", this.getRank());
        return json;
    }
    public void fromJSON(JSONObject json) throws Exception {
        if(json==null) return;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try{
            if(json.get("id") != null){
                this.setId(Integer.parseInt(json.get("id")+""));
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("pID") != null){
                this.setPID(Integer.parseInt(json.get("pID")+""));
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("title") != null){
                this.setTitle(json.get("title")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("firstPY") != null){
                this.setFirstPY(json.get("firstPY")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("rank") != null){
                this.setRank(Integer.parseInt(json.get("rank")+""));
            }
        }catch(Exception ex){
        }
    }
    public void fromMap(Map<String, String> json) throws Exception {
        if(json==null) return;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if(json.containsKey("id".toLowerCase())){
                this.setId(Integer.parseInt(json.get("id".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("pID".toLowerCase())){
                this.setPID(Integer.parseInt(json.get("pID".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("title".toLowerCase())){
                this.setTitle(json.get("title".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("firstPY".toLowerCase())){
                this.setFirstPY(json.get("firstPY".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("rank".toLowerCase())){
                this.setRank(Integer.parseInt(json.get("rank".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
    }
}
